<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>BMI测试页面</title>
</head>
<body>
<div>
    <h1>BMI身体质量指数测试</h1>
    <input type="text" placeholder="请输入身高(米)" v-model="height">
    <input type="text" placeholder="请输入体重(公斤)" v-model="weight">
    <input type="button" value="测试" @click="f()">
    <h3>结果:{{result}}</h3>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<script>
    let v = new Vue({
        el: "body>div",
        data: {
            result: "", height: "", weight: ""
        },
        methods: {
            f() {
                //发出异步请求
                axios.get("/bmi?height=" + v.height + "&weight=" + v.weight).then(function (response) {
                    switch (response.data) {
                        case 1:
                            v.result = "兄弟你瘦了";
                            break;
                        case 2:
                            v.result = "身体健康";
                            break;
                        case 3:
                            v.result = "微微胖";
                            break;
                        case 4:
                            v.result = "有点胖";
                            break;
                    }
                })
            }
        }
    })
</script>

</body>
</html>